package com.zuoye.T1;

import java.io.*;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/4/7 17:24
 * @description
 */
public class FileFunction {
    public static void copyFile(String fromFileName, String toFileName){

        try {
            if (isFileExist(fromFileName)){
                FileInputStream fis = new FileInputStream(fromFileName);
                FileOutputStream fos = new FileOutputStream(toFileName);

                byte[] buff = new byte[1024];
                int len = 0;
                while ((len = fis.read(buff))!=-1){
                    fos.write(buff,0,len);
                }
                fos.close();
                fis.close();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static boolean isFileExist(String fileName) {
        File file = new File(fileName);
        if (file.exists()){
            return true;
        }else {
            return false;
        }
    }

    public static void deleteFile(String name){
        File file = new File(name);
        file.delete();
    }
}
